package com.yuke.cloud.common.core.interceptor;

import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
 * <p>Company: Copyright (c) 2018. yuke All Rights Reserved. </br> </p>
 * <p>Title：yukemall </br> </p>
 * <p>com.yuke.cloud.common.core.interceptor Description TODO </br> </p>
 * @Author wg
 * @Date   2018/12/15 14:46
 */

/**
 * 当前端请求接口时，第一次是可能是Options 请求，进行处理，否则有可能出现401错误
 */
public class OptionsInterceptor implements HandlerInterceptor {
    private static final String OPTIONS = "OPTIONS";

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if(OPTIONS.equalsIgnoreCase(request.getMethod()))
        {
            response.setStatus(HttpStatus.OK.value());
//            return false;
            return true;
        }

        return true;
    }
}


